package com.yusi.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yusi.entity.Pathdis;
import com.yusi.entity.dto.RespPageBean;
import com.yusi.mapper.PathdisMapper;
import com.yusi.service.IPathdisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yusi
 * @since 2022-01-10
 */
@Service
public class PathdisServiceImpl extends ServiceImpl<PathdisMapper, Pathdis> implements IPathdisService {

    @Autowired
    private PathdisMapper pathdisMapper;

    @Override
    public RespPageBean getAirlines(Integer currentpage, Integer size, String airport1, String airport2, LocalDate[] beginDateScope) {
        //        分页查询的原理
//        1.先完成分页的配置
        Page<Pathdis> page = new Page<>(currentpage, size);
//        2.编写正常的sql语句但是不带分页语句
        IPage<Pathdis> employeeByPage = pathdisMapper.getAirlines(page,airport1,airport2,beginDateScope);
//        3.在进行分页查询的时候，会拦截sql语句，加上分页的语句，完成分页查询。
        RespPageBean respPageBean = new RespPageBean(employeeByPage.getTotal(), employeeByPage.getRecords());
        return respPageBean;
    }

//        return pathdisMapper.getAirlines(airport1,airport2);
}
